package cn.kgc.service.impl;

import cn.kgc.entity.Product;
import cn.kgc.mapper.ProductMapper;
import cn.kgc.service.ProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service("productService")
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public PageInfo<Product> queryProductList(String productName, Integer pageId) {
        //开启分页
        PageHelper.startPage(pageId,3);
        //按条件查询
        Example condition = new Example(Product.class);
        if(!StringUtils.isBlank(productName)){
            condition.and().andLike("productName","%"+productName+"%");
        }
        condition.orderBy("productDate").desc();
        //执行分页查询
        List<Product> productList = productMapper.selectByExample(condition);

        return new PageInfo<Product>(productList);
    }
}
